﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CMS.BLL;

public partial class Controls_Common_ctrLeftSide : System.Web.UI.UserControl
{
    private int nPageCount = 0;
    private int nCurrentLanguage = Support.GetCurrentLanguage() - 1;
    private int nDefaultLanguage = Support.GetDefaultLanguage();
    private int nPageSize = Config.PAGESIZE;
    private int nPageIndex = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindDataService();
            this.BindDataConsulting();
            this.BindDataTestimonial();
        }
    }

    private void BindDataService()
    {
        StaticPages objService = new StaticPages();
        DataTable dtbService = new DataTable();
        dtbService = objService.GetItemByPageCode("services");
        rptService.DataSource = dtbService;
        rptService.DataBind();
    }

    private void BindDataConsulting()
    {
        StaticPages objConsulting = new StaticPages();
        DataTable dtbConsulting = new DataTable();
        dtbConsulting = objConsulting.GetItemByPageCode("consulting");
        rptConsulting.DataSource = dtbConsulting;
        rptConsulting.DataBind();
    }

    private void BindDataTestimonial()
    {
        int nPageCount = 0;
        int nStatus = -1;
        int nDefLang = Support.GetDefaultLanguage();
        int CurrentPageIndex = 1;
        Testimonial objTestimonial = new Testimonial();
        DataTable dtbTestimonial = new DataTable();
        dtbTestimonial = objTestimonial.Search(0, nStatus, CurrentPageIndex, Config.PAGESIZE, ref nPageCount);
        rptTestimonial.DataSource = dtbTestimonial;
        rptTestimonial.DataSource = dtbTestimonial;
        rptTestimonial.DataBind();
    }

    protected void rptService_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
          if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
          {
              HyperLink lnkServiceParent = (HyperLink)e.Item.FindControl("lnkServiceParent");
              Repeater rptServiceChild = (Repeater)e.Item.FindControl("rptServiceChild");

              int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StaticPageID"));
              lnkServiceParent.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PageName1"));

              StaticPages objStaticPageChild1 = new StaticPages();
              DataTable dtbStaticPageChild1 = new DataTable();
              dtbStaticPageChild1 = objStaticPageChild1.Search(string.Empty, nID, nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, nPageIndex, nPageSize, ref nPageCount);


              int nItemCount = dtbStaticPageChild1.Rows.Count;

              if (nItemCount > 0)
              {
                  rptServiceChild.Visible = true;
                  rptServiceChild.DataSource = dtbStaticPageChild1;
                  rptServiceChild.DataBind();
                  //lnkServiceParent.NavigateUrl = "#";
              }
              else
              {
                  rptServiceChild.Visible = false;
                  lnkServiceParent.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nID;
              }
          }
    }
    protected void rptServiceChild_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkServiceServiceChild = (HyperLink)e.Item.FindControl("lnkServiceServiceChild");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StaticPageID"));

            lnkServiceServiceChild.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PageName"));
            lnkServiceServiceChild.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nID;
        }
    }
    protected void rptConsulting_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkConsultingParent = (HyperLink)e.Item.FindControl("lnkConsultingParent");
            Repeater rptConsulting = (Repeater)e.Item.FindControl("rptConsulting");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StaticPageID"));
            lnkConsultingParent.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PageName1"));

            StaticPages objStaticPageChild1 = new StaticPages();
            DataTable dtbStaticPageChild1 = new DataTable();
            dtbStaticPageChild1 = objStaticPageChild1.Search(string.Empty, nID, nDefaultLanguage, nCurrentLanguage, EnumeType.ACTIVE, nPageIndex, nPageSize, ref nPageCount);


            int nItemCount = dtbStaticPageChild1.Rows.Count;

            if (nItemCount > 0)
            {
                rptConsulting.Visible = true;
                rptConsulting.DataSource = dtbStaticPageChild1;
                rptConsulting.DataBind();
                //lnkConsultingParent.NavigateUrl = "#";
            }
            else
            {
                rptConsulting.Visible = false;
                lnkConsultingParent.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nID;
            }
        }
    }
    protected void rptConsulting_ItemDataBound1(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkConsultingChild = (HyperLink)e.Item.FindControl("lnkConsultingChild");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "StaticPageID"));

            lnkConsultingChild.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "PageName"));
            lnkConsultingChild.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nID;
        }
    }
    protected void rptTestimonial_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblcontentTesti = (Label)e.Item.FindControl("lblcontentTesti");
            Label lblNameTesti = (Label)e.Item.FindControl("lblNameTesti");
            Label lblpositionTesti = (Label)e.Item.FindControl("lblpositionTesti");
            lblcontentTesti.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TestimonialContent"));
            lblNameTesti.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ClientName"));
            lblpositionTesti.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ClientPosition"));

        }
    }
}